<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>操作节点</title>
</head>
<body>
    <form action="#">
        <p><textarea id="textArea" rows="5" cols="30"></textarea></p>
        <input type="submit" value="Add some text to the page"/>
    </form>
    <a id="deleteNode" href="#">Delete last paragraph</a>

<script type="text/javascript">
    window.onload=initAll();

    function initAll(){
        document.getElementsByTagName("form")[0].onsubmit = function(){return addNode()};
        document.getElementById("deleteNode").onclick = delNode;
    }

    function addNode(){
        var inText = document.getElementById("textArea").value;
        var newText = document.createTextNode(inText);

        var newGraf = document.createElement("p");
        newGraf.appendChild(newText);

        var docBody = document.getElementsByTagName("body")[0];
        docBody.appendChild(newGraf);

        return false;
    }

    function delNode(){
        var allGrafs = document.getElementsByTagName("p");
        if(allGrafs.length > 1){
            var lastGraf = allGrafs.item(allGrafs.length - 1);
            var docBody = document.getElementsByTagName("body")[0];
            docBody.removeChild(lastGraf);
        }
        else{
            alert("Nothing to remove!");
        }

        return false;
    }

</script>
</body>
</html>